package Chapter10;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Demo03 {
    //商品列表:
    //电视机，2567元/台
    //洗衣机，3562元/台
    //冰箱，6573元/台
    //计算出商品总价，并输出总和
    public static void main(String[] args) {
        String filePath = "src/Chapter10/log3.txt";
        double totalPrice = 0;
        try (BufferedReader bufferedReader= new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                String[] parts = line.split("，");
                if (parts.length == 2) {
                    String priceStr = parts[1].replaceAll("[^0-9.]", "");
                    double price = Double.parseDouble(priceStr);
                    totalPrice += price;
                }
            }
            System.out.println("商品总价: " + totalPrice + "元");

        } catch (IOException e) {
            System.out.println("An error occurred: " + e.getMessage());
        }
    }

}
